unit uFrmDealerSelect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Grids, StdCtrls, usqls, gnugettext;

type
  TFrmDealerSelect = class(TForm)
    btn_OK: TButton;
    btn_Cancel: TButton;
    stg_Dealers: TStringGrid;
    img_Dealer: TImage;
    procedure btn_CancelClick(Sender: TObject);
    procedure btn_OKClick(Sender: TObject);
    procedure stg_DealersSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
    procedure stg_DealersClick(Sender: TObject);
  private
    m_TableId, m_TableZoneId: string;
    m_IsBar, m_IsCage: Boolean;
    { Private declarations }
  public
    { Public declarations }
    procedure ShowDealerForm(TableId, TournamentId, CashGameId, TableZoneId, SubjectID: string; IsCage: Boolean = false; IsBar: Boolean = false);
  end;

var
  FrmDealerSelect: TFrmDealerSelect;

implementation

uses umainutils, uutils;
{$R *.dfm}
{ TForm1 }

procedure TFrmDealerSelect.btn_CancelClick(Sender: TObject);
begin
  close();
end;

procedure TFrmDealerSelect.btn_OKClick(Sender: TObject);
begin
  if stg_Dealers.Cells[0, stg_Dealers.Row] <> '' then
  BEGIN
    if m_IsBar then
    begin
      InsertDataIntoDB('BAR_LOGGINS', 'USER_ID,IN_DATETIME', stg_Dealers.Cells[0, stg_Dealers.Row] + ',' + '(SELECT SYSDATE FROM DUAL)');
    end
    else if m_IsCage then
    begin
      InsertDataIntoDB('CAGE_LOGINS', 'USER_ID,IN_DATETIME', stg_Dealers.Cells[0, stg_Dealers.Row] + ',' + '(SELECT SYSDATE FROM DUAL)');
    end
    else
    begin
      if (m_TableZoneId <> '') and (m_TableId = '') then
      begin
        InsertDataIntoDB('TABLE_ZONE_SUBJECT_LOGINS', 'USER_ID,TABLE_ZONE_ID,IN_DATETIME', stg_Dealers.Cells[0, stg_Dealers.Row] + ',' + m_TableZoneId + ',' + '(SELECT SYSDATE FROM DUAL)');
      end
      else
      begin
        InsertDataIntoDB('TABLE_SUBJECT_LOGINS', 'USER_ID,TABLE_ID,IN_DATETIME', stg_Dealers.Cells[0, stg_Dealers.Row] + ',' + m_TableId + ',' + '(SELECT SYSDATE FROM DUAL)');
      end;
    END;
    close();
  END;
end;

procedure TFrmDealerSelect.ShowDealerForm(TableId, TournamentId, CashGameId, TableZoneId, SubjectID: string; IsCage, IsBar: Boolean);
var
  i: Integer;
  LoginForm: string;
begin
  m_TableId := TableId;
  m_TableZoneId := TableZoneId;
  m_IsBar := IsBar;
  m_IsCage := IsCage;
  if IsCage then
  begin
    self.Caption := _('Cashier login');
    LoginForm := LoginForm_Cage;
  end
  else if IsBar then
  begin
    self.Caption := _('Bar login');
    LoginForm := LoginForm_Bar;
  end
  else
  begin
    if TableZoneId <> '' then
    begin
      LoginForm := LoginForm_Hall;
      self.Caption := _('Inspector login');
    end
    else
    begin
      LoginForm := LoginForm_Table;
      self.Caption := _('Dealer login');
    end;
  end;
  umainutils.OraQueryMainUtils.close;
  umainutils.OraQueryMainUtils.SQL.Text := 'SELECT US.ID, US.NAME||'' ''||SURNAME AS SUBJECT FROM USERS US' +
    ' JOIN USER_HAS_PROFILE PR ON US.ID=PR.USER_ID JOIN LOGIN_FORM_PROFILES LFP ON LFP.PROFILE_ID=PR.PROFILE_ID' + ' JOIN LOGIN_FORMS LF ON LF.ID=LFP.LOGIN_FORM_ID WHERE LF.NAME=' + '''' +
    LoginForm + '''';
  umainutils.OraQueryMainUtils.Execute;
  i := 0;
  img_Dealer.Picture := nil;
  ClearStringGrid(stg_Dealers);
  while not umainutils.OraQueryMainUtils.Eof do
  begin
    stg_Dealers.Cells[0, i] := umainutils.OraQueryMainUtils.Field(0);
    stg_Dealers.Cells[1, i] := umainutils.OraQueryMainUtils.Field(1);
    inc(i);
    umainutils.OraQueryMainUtils.Next;
  end;
  stg_Dealers.ColWidths[0] := -1;
  stg_Dealers.ColWidths[1] := stg_Dealers.Width - 3; ;
  stg_Dealers.RowCount := i;
  ShowModal;
end;

procedure TFrmDealerSelect.stg_DealersClick(Sender: TObject);
begin
  stg_Dealers.Refresh;
end;

procedure TFrmDealerSelect.stg_DealersSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
begin
  if (stg_Dealers.Cells[0, ARow] <> '') then
  begin
    img_Dealer.Picture := GetImage(SQL_User_Picture + stg_Dealers.Cells[0, ARow], OraSessMainUtils);
  end;
  stg_Dealers.Refresh;
end;

end.
